<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : cabinetInf.xsl
    Created on : 14 octobre 2014, 09:59
    Author     : Elisa
    Description:
        Purpose of transformation follows.
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:act='http://www.ujf-grenoble.fr/l3miage/actes'
                 xmlns:cab="http://polytech.ujf-grenoble.fr/cabinet" version="1.0">
    <xsl:output method="html"/>

    <!-- TODO customize transformation rules 
         syntax recommendation http://www.w3.org/TR/xslt 
    -->
    <xsl:variable name="actes" select="document('actes.xml', /)/act:ngap"/>
    <xsl:param name="destinedId" select="001"/>   
    <xsl:template match="/">
        <html>
            <head>
                <title>cabinetInf.xsl</title>
                <link rel="stylesheet" type="text/css" href="css/cabinetInf.css"/>
                <script type="text/javascript" src="js/facture.js"></script>
                <script type="text/javascript" >
                    function openFacture(prenom, nom, actes) 
                    {
                        var width  = 500;
                        var height = 300;
                        if(window.innerWidth) {
                            var left = (window.innerWidth-width)/2;
                            var top = (window.innerHeight-height)/2;
                        }
                        else {
                            var left = (document.body.clientWidth-width)/2;
                            var top = (document.body.clientHeight-height)/2;
                        }
                        var factureWindow = window.open('','facture','menubar=yes, scrollbars=yes, top='+top+', left='+left+', width='+width+', height='+height+'');
                        factureText = afficherFacture(prenom, nom, actes); 
                        factureWindow.document.write(factureText);
                    }        
                </script>
            </head>
            <body>
                <h1>Bonjour <xsl:apply-templates select="./cab:cabinet/cab:infirmiers/cab:infirmier[@id = $destinedId]/cab:prenom"/></h1>
                <p>
                    Aujourd'hui, vous avez <xsl:value-of select="count(./cab:cabinet/cab:patients/cab:patient/cab:visite[@intervenant = $destinedId])"/> patients
                </p>
                
                    <table border="1" cellspacing="0" cellpadding="3">
                        <tr>
                            <th>Nom</th>
                            <th>Prénom</th>
                            <th>Adresse</th>
                            <th>Soins</th> 
                            <th>Facture</th>
                        </tr>
                        <xsl:apply-templates select="./cab:cabinet/cab:patients/cab:patient"/>
                    </table>
            </body>
        </html>
    </xsl:template>

    <xsl:template match="cab:prenom">
        <xsl:value-of select="."/>
    </xsl:template>
    
    <xsl:template match="cab:patient">
        <tr>
            <xsl:if test="cab:visite[@intervenant = $destinedId]">
                <td> <xsl:value-of select="cab:nom"/></td>
                <td><xsl:value-of select="cab:prenom"/></td>
                <td>
                    <xsl:value-of select="cab:adresse/cab:numero"/>
                    <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
                    <xsl:value-of select="cab:adresse/cab:rue"/><br/>
                    <xsl:value-of select="cab:adresse/cab:codePostal"/>
                    <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
                    <xsl:value-of select="cab:adresse/cab:ville"/>
                </td>
                <td>
                    <ul>
                        <xsl:apply-templates select="./cab:visite/cab:acte"/>
                    </ul>

                </td>
                <td>
                    <xsl:attribute name="onclick">
                        openFacture('<xsl:value-of select="cab:prenom"/>',
                                    '<xsl:value-of select="cab:nom"/>',
                                    '<xsl:value-of select="cab:visite/cab:acte/@id"/>')
                    </xsl:attribute>  
                    <input type="button" onclick="$onclick" value="Facture"/>

                </td>
                
            </xsl:if>
            
        </tr>  
       
    </xsl:template>
    
    
    <xsl:template match="cab:acte">
        <li>
            <xsl:variable name="idActeInf">
                 <xsl:value-of select="./@id"/>
            </xsl:variable>
            <xsl:value-of select="$actes/act:actes/act:acte[@id = $idActeInf]/text()"/>    
        </li>
    </xsl:template>
</xsl:stylesheet>
